package org.zfes.snowier.cloud.zbss.layer.tc.biz.service.impl;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;

import org.zfes.snowier.cloud.zbss.layer.tc.biz.service.IPercentageService;
import org.zfes.snowier.common.export.poi.excel.template.PoiTemplate;
import org.zfes.snowier.common.export.poi.excel.template.tags.ForeachTag;
import org.zfes.snowier.common.export.poi.excel.template.util.TagUtil;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.core.data.Record;
import org.zfes.snowier.core.util.ZDateUtil;
import org.zfes.snowier.core.util.ZStrUtil;
import org.zfes.snowier.core.util.datex.ZDateStyle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ExportServiceImpl {
	@Autowired
	IPercentageService cultureDeclarProjectService;

	
	public void doExportPojectNew(Map<String, Object> params,OutputStream output) {
		params.put("rows", 65535*50);
		params.put("page", 1);
		DataSet ds=cultureDeclarProjectService.loadPercentageDataSet(params);
		
		List<Record> recordList=ds.getRecordRows();
		long count=ds.getTotal();
		
		TagUtil.registerTag(ForeachTag.class);
		if(recordList!=null) {
			recordList.forEach(val->{
				String checkStatus=String.valueOf(val.get("checkStatus"));
				if(ZStrUtil.hasText(checkStatus)&&!"-".equals(checkStatus)&&!"null".equals(checkStatus)) {
					if("1".equals(checkStatus)){
						val.put("checkStatus", "未审核");
					}else {
						val.put("checkStatus", "已审核");
					}
				}
				
				String caseLiAnStatus=String.valueOf(val.get("caseLiAnStatus"));
				if(ZStrUtil.hasText(caseLiAnStatus)&&!"-".equals(caseLiAnStatus)&&!"null".equals(caseLiAnStatus)) {
					if("1".equals(caseLiAnStatus)){
						val.put("caseLiAnStatus", "未结清");
					}else if("2".equals(caseLiAnStatus)){
						val.put("caseLiAnStatus", "已结清");
					}
				}
				
				String caseJieAnStatus=String.valueOf(val.get("caseJieAnStatus"));
				if(ZStrUtil.hasText(caseJieAnStatus)&&!"-".equals(caseJieAnStatus)&&!"null".equals(caseJieAnStatus)) {
					if("1".equals(caseJieAnStatus)){
						val.put("caseJieAnStatus", "未结清");
					}else if("2".equals(caseJieAnStatus)){
						val.put("caseJieAnStatus", "已结清");
					}
				}
				
				
				String caseTuiFeiStatus=String.valueOf(val.get("caseTuiFeiStatus"));
				if(ZStrUtil.hasText(caseTuiFeiStatus)&&!"-".equals(caseTuiFeiStatus)&&!"null".equals(caseTuiFeiStatus)) {
					if("1".equals(caseTuiFeiStatus)){
						val.put("caseTuiFeiStatus", "未结清");
					}else if("0".equals(caseTuiFeiStatus)){
						val.put("caseTuiFeiStatus", "未发生");
					}else if("2".equals(caseTuiFeiStatus)){
						val.put("caseTuiFeiStatus", "已结清");
					}else if("2".equals(caseTuiFeiStatus)){
						val.put("caseTuiFeiStatus", "终止委托");
					}
				}
				
			
				
			});
		}
		try {

			InputStream resource = getClass().getResourceAsStream("/exporttpl.xlsx");
			PoiTemplate temp =PoiTemplate.instance(resource,output,true);

			temp.addValue("recordList", recordList);
	
			temp.writeExcel();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
	}
	
	

}
